package b.i.k;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.AccessibilityDelegate;
import android.view.View.OnApplyWindowInsetsListener;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.WindowInsets;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/* compiled from: ViewCompat */
public class o {
    public static WeakHashMap<View, t> a = null;
    public static Field b;
    public static boolean c = false;
    public static ThreadLocal<Rect> d;

    /* compiled from: ViewCompat */
    public class a implements OnApplyWindowInsetsListener {
        public final /* synthetic */ k a;

        public a(k kVar) {
            this.a = kVar;
        }

        public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
            Objects.requireNonNull(windowInsets);
            return this.a.a(view, new x(windowInsets)).i();
        }
    }

    /* compiled from: ViewCompat */
    public static abstract class b<T> {
        public final int a;
        public final Class<T> b;
        public final int c;

        public b(int i, Class<T> cls, int i2) {
            this.a = i;
            this.b = cls;
            this.c = i2;
        }

        public boolean a(Boolean bool, Boolean bool2) {
            boolean z;
            boolean booleanValue = bool == null ? false : bool.booleanValue();
            if (bool2 == null) {
                z = false;
            } else {
                z = bool2.booleanValue();
            }
            if (booleanValue == z) {
                return true;
            }
            return false;
        }

        public abstract T b(View view);

        public T c(View view) {
            if ((VERSION.SDK_INT >= this.c ? 1 : null) != null) {
                return b(view);
            }
            Object tag = view.getTag(this.a);
            return this.b.isInstance(tag) ? tag : null;
        }

        public b(int i, Class<T> cls, int i2, int i3) {
            this.a = i;
            this.b = cls;
            this.c = i3;
        }
    }

    /* compiled from: ViewCompat */
    public interface c {
        boolean a(View view, KeyEvent keyEvent);
    }

    /* compiled from: ViewCompat */
    public static class d {
        public static final ArrayList<WeakReference<View>> d = new ArrayList();
        public WeakHashMap<View, Boolean> a = null;
        public SparseArray<WeakReference<View>> b = null;
        public WeakReference<KeyEvent> c = null;

        public final View a(View view, KeyEvent keyEvent) {
            WeakHashMap weakHashMap = this.a;
            if (weakHashMap != null && weakHashMap.containsKey(view)) {
                if (view instanceof ViewGroup) {
                    ViewGroup viewGroup = (ViewGroup) view;
                    for (int childCount = viewGroup.getChildCount() - 1; childCount >= 0; childCount--) {
                        View a = a(viewGroup.getChildAt(childCount), keyEvent);
                        if (a != null) {
                            return a;
                        }
                    }
                }
                if (b(view, keyEvent)) {
                    return view;
                }
            }
            return null;
        }

        public final boolean b(View view, KeyEvent keyEvent) {
            ArrayList arrayList = (ArrayList) view.getTag(2131297025);
            if (arrayList != null) {
                for (int size = arrayList.size() - 1; size >= 0; size--) {
                    if (((c) arrayList.get(size)).a(view, keyEvent)) {
                        return true;
                    }
                }
            }
            return false;
        }
    }

    static {
        AtomicInteger atomicInteger = new AtomicInteger(1);
        WeakHashMap weakHashMap = new WeakHashMap();
    }

    public static t a(View view) {
        if (a == null) {
            a = new WeakHashMap();
        }
        t tVar = (t) a.get(view);
        if (tVar != null) {
            return tVar;
        }
        tVar = new t(view);
        a.put(view, tVar);
        return tVar;
    }

    public static void b(View view, int i) {
        view.offsetLeftAndRight(i);
        if (view.getVisibility() == 0) {
            float translationY = view.getTranslationY();
            view.setTranslationY(1.0f + translationY);
            view.setTranslationY(translationY);
            ViewParent parent = view.getParent();
            if (parent instanceof View) {
                r((View) parent);
            }
        }
    }

    public static void c(View view, int i) {
        view.offsetTopAndBottom(i);
        if (view.getVisibility() == 0) {
            float translationY = view.getTranslationY();
            view.setTranslationY(1.0f + translationY);
            view.setTranslationY(translationY);
            ViewParent parent = view.getParent();
            if (parent instanceof View) {
                r((View) parent);
            }
        }
    }

    public static x d(View view, x xVar) {
        WindowInsets i = xVar.i();
        return (i == null || view.dispatchApplyWindowInsets(i).equals(i)) ? xVar : new x(i);
    }

    public static boolean e(View view, KeyEvent keyEvent) {
        boolean z = false;
        if (VERSION.SDK_INT >= 28) {
            return false;
        }
        ArrayList arrayList = d.d;
        d dVar = (d) view.getTag(2131297024);
        if (dVar == null) {
            dVar = new d();
            view.setTag(2131297024, dVar);
        }
        if (keyEvent.getAction() == 0) {
            Boolean bool = Boolean.TRUE;
            WeakHashMap weakHashMap = dVar.a;
            if (weakHashMap != null) {
                weakHashMap.clear();
            }
            ArrayList arrayList2 = d.d;
            if (!arrayList2.isEmpty()) {
                synchronized (arrayList2) {
                    if (dVar.a == null) {
                        dVar.a = new WeakHashMap();
                    }
                    int size = arrayList2.size();
                    while (true) {
                        size--;
                        if (size < 0) {
                            break;
                        }
                        ArrayList arrayList3 = d.d;
                        View view2 = (View) ((WeakReference) arrayList3.get(size)).get();
                        if (view2 == null) {
                            arrayList3.remove(size);
                        } else {
                            dVar.a.put(view2, bool);
                            for (ViewParent parent = view2.getParent(); parent instanceof View; parent = parent.getParent()) {
                                dVar.a.put((View) parent, bool);
                            }
                        }
                    }
                }
            }
        }
        view = dVar.a(view, keyEvent);
        if (keyEvent.getAction() == 0) {
            int keyCode = keyEvent.getKeyCode();
            if (!(view == null || KeyEvent.isModifierKey(keyCode))) {
                if (dVar.b == null) {
                    dVar.b = new SparseArray();
                }
                dVar.b.put(keyCode, new WeakReference(view));
            }
        }
        if (view != null) {
            z = true;
        }
        return z;
    }

    public static a f(View view) {
        AccessibilityDelegate g = g(view);
        if (g == null) {
            return null;
        }
        if (g instanceof b.i.k.a.a) {
            return ((b.i.k.a.a) g).a;
        }
        return new a(g);
    }

    public static AccessibilityDelegate g(View view) {
        if (VERSION.SDK_INT >= 29) {
            return view.getAccessibilityDelegate();
        }
        AccessibilityDelegate accessibilityDelegate = null;
        if (!c) {
            if (b == null) {
                try {
                    Field declaredField = View.class.getDeclaredField("mAccessibilityDelegate");
                    b = declaredField;
                    declaredField.setAccessible(true);
                } catch (Throwable unused) {
                    c = true;
                }
            }
            try {
                Object obj = b.get(view);
                if (obj instanceof AccessibilityDelegate) {
                    accessibilityDelegate = (AccessibilityDelegate) obj;
                }
            } catch (Throwable unused2) {
                c = true;
            }
        }
        return accessibilityDelegate;
    }

    public static Rect h() {
        if (d == null) {
            d = new ThreadLocal();
        }
        Rect rect = (Rect) d.get();
        if (rect == null) {
            rect = new Rect();
            d.set(rect);
        }
        rect.setEmpty();
        return rect;
    }

    public static void i(View view, int i) {
        if (((AccessibilityManager) view.getContext().getSystemService("accessibility")).isEnabled()) {
            Object obj = ((CharSequence) new q(2131297020, CharSequence.class, 8, 28).c(view)) != null ? 1 : null;
            if (view.getAccessibilityLiveRegion() != 0 || (obj != null && view.getVisibility() == 0)) {
                AccessibilityEvent obtain = AccessibilityEvent.obtain();
                obtain.setEventType(obj != null ? 32 : 2048);
                obtain.setContentChangeTypes(i);
                view.sendAccessibilityEventUnchecked(obtain);
            } else if (view.getParent() != null) {
                try {
                    view.getParent().notifySubtreeAccessibilityStateChanged(view, view, i);
                } catch (AbstractMethodError e) {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.append(view.getParent().getClass().getSimpleName());
                    stringBuilder.append(" does not fully implement ViewParent");
                    Log.e("ViewCompat", stringBuilder.toString(), e);
                }
            }
        }
    }

    public static void j(View view, int i) {
        if (VERSION.SDK_INT >= 23) {
            view.offsetLeftAndRight(i);
            return;
        }
        Rect h = h();
        int i2 = 0;
        ViewParent parent = view.getParent();
        if (parent instanceof View) {
            View view2 = (View) parent;
            h.set(view2.getLeft(), view2.getTop(), view2.getRight(), view2.getBottom());
            i2 = h.intersects(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()) ^ 1;
        }
        b(view, i);
        if (i2 != 0 && h.intersect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())) {
            ((View) parent).invalidate(h);
        }
    }

    public static void k(View view, int i) {
        if (VERSION.SDK_INT >= 23) {
            view.offsetTopAndBottom(i);
            return;
        }
        Rect h = h();
        int i2 = 0;
        ViewParent parent = view.getParent();
        if (parent instanceof View) {
            View view2 = (View) parent;
            h.set(view2.getLeft(), view2.getTop(), view2.getRight(), view2.getBottom());
            i2 = h.intersects(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()) ^ 1;
        }
        c(view, i);
        if (i2 != 0 && h.intersect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())) {
            ((View) parent).invalidate(h);
        }
    }

    public static x l(View view, x xVar) {
        WindowInsets i = xVar.i();
        if (i == null) {
            return xVar;
        }
        WindowInsets onApplyWindowInsets = view.onApplyWindowInsets(i);
        return !onApplyWindowInsets.equals(i) ? new x(onApplyWindowInsets) : xVar;
    }

    public static void m(int i, View view) {
        List list = (ArrayList) view.getTag(2131297017);
        if (list == null) {
            list = new ArrayList();
            view.setTag(2131297017, list);
        }
        for (int i2 = 0; i2 < list.size(); i2++) {
            if (((b.i.k.y.b.a) list.get(i2)).a() == i) {
                list.remove(i2);
                return;
            }
        }
    }

    public static void n(View view, b.i.k.y.b.a aVar, CharSequence charSequence, b.i.k.y.d dVar) {
        b.i.k.y.b.a aVar2 = new b.i.k.y.b.a(null, aVar.b, null, dVar, aVar.c);
        a f = f(view);
        if (f == null) {
            f = new a();
        }
        p(view, f);
        m(aVar2.a(), view);
        List list = (ArrayList) view.getTag(2131297017);
        if (list == null) {
            list = new ArrayList();
            view.setTag(2131297017, list);
        }
        list.add(aVar2);
        i(view, 0);
    }

    public static void o(View view, @SuppressLint({"ContextFirst"}) Context context, int[] iArr, AttributeSet attributeSet, TypedArray typedArray, int i, int i2) {
        if (VERSION.SDK_INT >= 29) {
            view.saveAttributeDataForStyleable(context, iArr, attributeSet, typedArray, i, i2);
        }
    }

    public static void p(View view, a aVar) {
        AccessibilityDelegate accessibilityDelegate;
        if (aVar == null && (g(view) instanceof b.i.k.a.a)) {
            aVar = new a();
        }
        if (aVar == null) {
            accessibilityDelegate = null;
        } else {
            accessibilityDelegate = aVar.b;
        }
        view.setAccessibilityDelegate(accessibilityDelegate);
    }

    public static void q(View view, k kVar) {
        if (kVar == null) {
            view.setOnApplyWindowInsetsListener(null);
        } else {
            view.setOnApplyWindowInsetsListener(new a(kVar));
        }
    }

    public static void r(View view) {
        float translationY = view.getTranslationY();
        view.setTranslationY(1.0f + translationY);
        view.setTranslationY(translationY);
    }
}
